home *** CD-ROM | disk | FTP | other *** search
- # Source Generated with Decompyle++
- # File: in.pyc (Python 2.2)
-
- '''
- /***************************************************************************
-
- \tAuthor \t\t\t:Charles B. Cosse
- \t
- \tEmail\t\t\t:ccosse@asymptopia.com
- \t\t\t\t\t
- \t\t\t\t\t
- \tCopyright\t\t:(C) 2002,2003 Asymptopia Software.
- \t
- ***************************************************************************/
- /***************************************************************************
- Validator.py
-
- ***************************************************************************/
-
- /***************************************************************************
- * *
- * This program is free software; you can redistribute it and/or modify *
- * it under the terms of the GNU General Public License as published by *
- * the Free Software Foundation; either version 2 of the License, or *
- * (at your option) any later version. (Please note that if you use this *
- * code you must give credit by including the Author and Copyright *
- * info at the top of this file). *
- ***************************************************************************/
- '''
- import os
- import pygame
- from pygame.locals import *
-
- class Validator:
- '''Validator has game model.
- \t
- \t'''
-
- def __init__(self, board, game):
- self.board = board
- self.game = game
-
-
- def validate(self, submission):
- if len(submission) == 0:
- return 0
-
- board = self.board
- MinM = board.M
- MinN = board.N
- for spot in submission:
- if spot.M <= MinM and spot.N <= MinN:
- MinM = spot.M
- MinN = spot.N
-
-
- try_above = 1
- while 1:
- if MinN == 0:
- break
- elif board.get_spotMN(MinM, MinN - 1).guest != None:
- MinN = MinN - 1
- try_above = 0
- else:
- break
- while 1:
- if not try_above:
- break
- elif MinM == 0:
- break
- elif board.get_spotMN(MinM - 1, MinN).guest != None:
- MinM = MinM - 1
- else:
- break
- MaxM = 0
- MaxN = 0
- for spot in submission:
- if spot.M >= MaxM and spot.N >= MaxN:
- MaxM = spot.M
- MaxN = spot.N
-
-
- try_below = 1
- while 1:
- if MaxN == board.N - 1:
- break
- elif board.get_spotMN(MaxM, MaxN + 1).guest != None:
- MaxN = MaxN + 1
- try_below = 0
- else:
- break
- while 1:
- if not try_below:
- break
- elif MaxM == board.M - 1:
- break
- elif board.get_spotMN(MaxM + 1, MaxN).guest != None:
- MaxM = MaxM + 1
- else:
- break
- if MaxM - MinM > 0 and MaxN - MinN > 0:
- return 0
- elif MaxM - MinM > 0:
- exprtype = 'col'
- elif MaxN - MinN > 0:
- exprtype = 'row'
- elif MaxN - MinN == 0:
- return 0
- else:
- return 0
- if exprtype == 'row':
- for idx in range(MinN, MaxN + 1):
- this_idx_okay = 0
- for spot in submission:
- if spot.N == idx:
- this_idx_okay = 1
-
-
- if board.get_spotMN(MinM, idx).guest != None:
- this_idx_okay = 1
-
- if this_idx_okay == 0:
- return 0
-
-
- elif exprtype == 'col':
- for idx in range(MinM, MaxM + 1):
- this_idx_okay = 0
- for spot in submission:
- if spot.M == idx:
- this_idx_okay = 1
-
-
- if board.get_spotMN(idx, MinN).guest != None:
- this_idx_okay = 1
-
- if this_idx_okay == 0:
- return 0
-
-
-
- expr = ''
- if exprtype == 'row':
- for idx in range(MinN, MaxN + 1):
- if board.get_spotMN(MinM, idx).guest != None:
- expr = expr + board.get_spotMN(MinM, idx).guest.str_val
- continue
- else:
- for spot in submission:
- if spot.N == idx:
- expr = expr + spot.guest.str_val
- continue
-
-
-
- elif exprtype == 'col':
- for idx in range(MinM, MaxM + 1):
- if board.get_spotMN(idx, MinN).guest != None:
- expr = expr + board.get_spotMN(idx, MinN).guest.str_val
- else:
- for spot in submission:
- if spot.M == idx:
- expr = expr + spot.guest.str_val
-
-
-
-
- if expr.count('=') == 0:
- return 0
-
- for even_value in [
- 0,
- 2,
- 4,
- 6,
- 8,
- 10,
- 12,
- 14,
- 16,
- 18,
- 20]:
- length = len(expr)
- if expr.count('10'):
- length = length - expr.count('10')
-
- if expr.count('11'):
- length = length - expr.count('11')
-
- if expr.count('12'):
- length = length - expr.count('12')
-
- if expr.count('13'):
- length = length - expr.count('13')
-
- if expr.count('14'):
- length = length - expr.count('14')
-
- if expr.count('15'):
- length = length - expr.count('15')
-
- if expr.count('20'):
- length = length - expr.count('20')
-
- if length == even_value:
- return 0
-
-
- expr = expr.replace('=', '==')
-
- try:
- rval = eval(expr)
- except:
- return 0
-
- if rval == 0:
- return 0
-
- head_spot = None
- for spot in submission:
- if spot.M == MinM and spot.N == MinN:
- head_spot = spot
-
-
- if not head_spot:
- head_spot = board.get_spotMN(MinM, MinN)
-
- head_spot.AMHEAD = 1
- if exprtype == 'row':
- head_spot.AMROWEXPR = 1
- head_spot.ROWEXPRLENGTH = (MaxN - MinN) + 1
-
- if exprtype == 'col':
- head_spot.AMCOLEXPR = 1
- head_spot.COLEXPRLENGTH = (MaxM - MinM) + 1
-
- if exprtype == 'row':
- multiplier = 1
- score = 0
- for nidx in range(MinN, MaxN + 1):
- spot2check = board.get_spotMN(MinM, nidx)
- if spot2check.TYPE == '2XL':
- score = score + 2
- elif spot2check.TYPE == '2XW':
- score = score + 1
- multiplier = multiplier * 2
- elif spot2check.TYPE == '3XL':
- score = score + 3
- elif spot2check.TYPE == '3XW':
- score = score + 1
- multiplier = multiplier * 3
- else:
- score = score + 1
-
- score = score * multiplier
- self.game.playerscore = self.game.playerscore + score
- for n in range(MinN + 1, MaxN + 1):
- if board.check4guest(MinM, n):
- spot2check = board.get_spotMN(MinM, n)
- if spot2check.AMHEAD and spot2check.AMROWEXPR:
- spot2check.AMROWEXPR = 0
- spot2check.ROWEXPRLENGTH = 0
- if spot2check.AMCOLEXPR:
- pass
- else:
- spot2check.AMHEAD = 0
-
-
-
-
- if exprtype == 'col':
- multiplier = 1
- score = 0
- for midx in range(MinM, MaxM + 1):
- spot2check = board.get_spotMN(midx, MinN)
- if spot2check.TYPE == '2XL':
- score = score + 2
- elif spot2check.TYPE == '2XW':
- score = score + 1
- multiplier = multiplier * 2
- elif spot2check.TYPE == '3XL':
- score = score + 3
- elif spot2check.TYPE == '3XW':
- score = score + 1
- multiplier = multiplier * 3
- else:
- score = score + 1
-
- score = score * multiplier
- self.game.playerscore = self.game.playerscore + score
- for m in range(MinM + 1, MaxM + 1):
- if board.check4guest(m, MinN):
- spot2check = board.get_spotMN(m, MinN)
- if spot2check.AMHEAD and spot2check.AMCOLEXPR:
- spot2check.AMCOLEXPR = 0
- spot2check.COLEXPRLENGTH = 0
- if spot2check.AMROWEXPR:
- pass
- else:
- spot2check.AMHEAD = 0
-
-
-
-
- return 1
-
-
-